package me.sdevil507.biz.fruit.po;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;
import me.sdevil507.supports.jpa.BaseJpaSnowflakeIdEntity;
import me.sdevil507.supports.upload.po.AttachFile;
import org.hibernate.annotations.Formula;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @program: tips_back_end
 * @description: 成果
 * @author: kzl
 * @create: 2020-06-23 10:31
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(ignoreUnknown = true)
@Entity
@Table(name = "biz_fruit")
public class FruitPO extends BaseJpaSnowflakeIdEntity {


    /**
     * 初始分支/版本
     */
    @Column(name="init_fruit_id")
    private Long initFruitId;

    /**
     *  1.连续性内部资料管理
     *  2.内参
     *  3.报告
     *  4.政策咨询
     *  5.报纸/网络
     *  6.论文
     *  7.图书
     *  8.荣誉
     *  9.其他
     */
    @Column
    private String type;

    /**
     * 刊物类型
     */
    @Column
    private String publicationType;

    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=publication_type and t.type_key='publicationType' and t.is_del = 0)")
    private String  publicationTypeName;

    /**
     * 报告类型
     */
    @Column
    private String reportType;

//    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=report_type and t.type_key='ReportType')")
//    private String reportTypeName;
    /**
     * 政策咨询报告类型
     */
    @Column
    private String policyType;

    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=policy_type and t.type_key='policyType' and t.is_del = 0)")
    private String policyTypeName;

    /**
     * 著作方式
     */
    @Column
    private String writeType;

    /**
     * 著作方式
     */
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=write_type and t.type_key='writeType' and t.is_del = 0)")
    private String writeTypeName;

    /**
     * 论文类型
     */
    @Column
    private String paperType;

//    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=paper_type and t.type_key='paperType' and t.is_del = 0)")
//    private String paperTypeName;

    /**
     * 图书类型
     */
    @Column
    private String bookType;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=book_type and t.type_key='bookType' and t.is_del = 0)")
    private String bookTypeName;

    /**
     * 报告名称/论文名称/著作名称/媒体文章/微信/获奖作品
    */
    @Column
    private String name;

    @Column
    private String englishName;
    /**刊物照片**/
    @Column
    private String photo;

    /***主办单位**/
    @Column
    private String organizer;

    /**主管单位**/
    @Column
    private String competentUnit;

    /**主编**/
    @Column
    private String chiefEditor;

    /**创办日期**/
    @Column
    private Date createDate;

    /**期号 期次**/
    @Column
    private String issueNumber;

    /**辑号**/
    @Column
    private String serialNumber;

    /**语种**/
    @Column
    private String languages;

    /**出版周期**/
    @Column
    private String  pubCycle;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=pub_cycle and t.type_key='pubCycle' and t.is_del = 0)")
    private String  pubCycleName;

    /**出版地**/
    @Column
    private String  pubPlace;

    /**发行量**/
    @Column
    private String  circulation;

    /**发行对象**/
    @Column
    private String  pubObject;


    @OneToMany(targetEntity = FruitAuthorPO.class, cascade= CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn(name="fruitId")
    @OrderBy("ranking ASC")
    private List<FruitAuthorPO> authorPOList =new ArrayList<>();

    @OneToMany(targetEntity = FruitLeaderPO.class, cascade= CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn(name="fruitId", referencedColumnName = "init_fruit_id")
    private List<FruitLeaderPO> leaderPOS =new ArrayList<>();

    /**相关附件**/
    @OneToMany(targetEntity = AttachFile.class, cascade= CascadeType.MERGE, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn(name="relationId")
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<AttachFile> attFiles =new ArrayList<>();

    /**感谢信和证明**/
    @OneToMany(targetEntity = FruitProvePO.class, cascade= CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn(name="fruitId", referencedColumnName = "init_fruit_id")
    private List<FruitProvePO> proveList =new ArrayList<>();

    /**合作单位信息**/
    @OneToMany(targetEntity = FruitCooInfoPO.class, cascade= CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn(name="fruitId", referencedColumnName = "init_fruit_id")
    private List<FruitCooInfoPO> cooInfoList =new ArrayList<>();

    /**报送信息**/
    @OneToMany(targetEntity = FruitSubPO.class, cascade= CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn(name="fruitId", referencedColumnName = "init_fruit_id")
    private List<FruitSubPO> subList =new ArrayList<>();

    /**项目成员信息**/
    @OneToMany(targetEntity = FruitMemberPO.class, cascade= CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn(name="fruitId", referencedColumnName = "init_fruit_id")
    private List<FruitMemberPO> memberList =new ArrayList<>();

    /**子项目信息**/
    @OneToMany(targetEntity = FruitSubprojectrPO.class, cascade= CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @JoinColumn(name="fruitId", referencedColumnName = "init_fruit_id")
    private List<FruitSubprojectrPO> subprojectList =new ArrayList<>();

    /**完成方式
     *1.独立完成 2.合作完成
     * **/
    @Column
    private String  completeMethod;

    /**
     * 完成时间
     */
    @Column
    private Date completionTime;


    /**
     * 报告来源 1.课堂产生 2.单独生成
     */
    @Column
    private String  source;

    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=source and t.type_key='ReportSource' and t.is_del = 0)")
    private String  sourceName;
    /**
     * 课题id
     */
    @Column
    private String  topicId;
    @Formula("(select t.name from biz_fruit as t  where t.id in (select p.fruit_id from biz_project p where p.id=topic_id))")
    private String  topicName;

    /**
     * 课题负责人id
     */
    @Column
    private String  topicLeader;
//    @Formula("(select t.real_name from biz_org_user as t  where t.id=topic_leader)")
//    private String  topicLeaderName;

    /**
     * 关键字
     */
    @Column
    private String  keyword;

    /**
     * 起草时间
     */
    @Column
    private Date  draftTime;


    /**
     * 委托方单位
     */
    @Column
    private String  client;


    /**
     * 委托方类型
     */
    @Column
    private String  clientType;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=client_type and t.type_key='clientType' and t.is_del = 0)")
    private String  clientTypeName;

    /**
     * 委托方等级--活动级别
     */
    @Column
    private String  clientLevel;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=client_level and t.type_key='ClientLevel' and t.is_del = 0)")
    private String  clientLevelName;


    /**
     * 刊登级别
     */
    @Column
    private String publicationLevel;


    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=publication_level and t.type_key='PubLevel' and t.is_del = 0)")
    private String publicationLevelName;

    /**
     * 期刊名称
     */
    @Column
    private String journalName;

    /**
     * 刊登时间/出版时间/获奖时间
     */
    @Column
    private Date pubTime;

    /**
     * 期刊类别
     */
    @Column
    private String journalType;

    /**
     * 期刊类别名称
     */
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=journal_type and t.type_key='journalType' and t.is_del = 0)")
    private String journalTypeName;

    /**
     * 阅读量
     */
    @Column
    private String readNumber;

    /**
     * 链接
     */
    @Column
    private String linkUrl;

    /**
     * 摘要
     */
    @Column
    private String summary;

    /**
     * 研究领域
     */
    @Column
    private String field;

    /**
     * 期次
     */
    @Column
    private String period;

    /**
     * 论文收录情况
     */
    @Column
    private String colPapers;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=col_papers and t.type_key='journalType' and t.is_del = 0)")
    private String colPapersName;

    /**
     * 论文转载情况
     */
    @Column
    private String reprint;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=reprint and t.type_key='Reprint' and t.is_del = 0)")
    private String reprintName;

    @Column
    private String reprintNper;

    /**
     * 是否删除
     */
    @Column(nullable = false)
    private Boolean  isDel= false;

    /**
     * 是否公开 0:是  1:否
     */
    @Column
    private String isPublic="0";

    /**
     * 创建时间
     */
    @Column
    private Date createTime = new Date();

    /**
     * 更新时间
     */
    @Column
    private Date updateTime = new Date();

    /**
     * 智库id
     */
    @Column
    private Long orgId;
    @Formula("(SELECT bf.name_zh from biz_org bf where bf.id = org_id)")
    private String orgName;

    /**
     * 平台操作用户id
     */
    @Column
    private Long userId;

    /**
     * 平台操作用户姓名
     */
    @Column
    private String userName;

    /**
     * 出版社
     */
    @Column
    private String press;

    /**
     * ISBN
     */
    @Column
    private String isbn;

    /**
     * 版次
     */
    @Column
    private String edition;

    /**
     * 奖项
     */
    @Column
    private String awards;

    /**
     * 颁奖单位
     */
    @Column
    private String grantUnit;

    /**
     * 获奖级别
     */
    @Column
    private String awardsLevel;

    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=awards_level and t.type_key='AwardLevel' and t.is_del = 0)")
    private String awardsLevelName;


    /**
     * 媒体类别
     */
    @Column
    private String  mediaType;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=media_type and t.type_key='MediaType' and t.is_del = 0)")
    private String  mediaTypeName;



    /**
     * 荣誉类别
     */
    @Column
    private String  honorType;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=honor_type and t.type_key='HonorType' and t.is_del = 0)")
    private String  honorTypeName;


    /**
     * 期刊网址
     */
    @Column
    private String website;
    /**
     * 开本
     */
    @Column
    private String bookSize;
    /**
     * 备注
     */
    @Column
    private String remark;

    /**
     * 邮发代号
     */
    @Column
    private String postalCode;

    /**
     * 是否公开
     */
    @Column
    private Boolean isOpen;

    /**
     * 是否以外文发布或在国际场合发布
     */
    @Column
    private Boolean isForeign;

    /**
     * 密级
     */
    @Column
    private String secretsType;

    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=secrets_type and t.type_key='SecretsType' and t.is_del = 0)")
    private String secretsTypeName;

    /**
     * 活动成果类型 1：出席会议 2：接受采访 3：考察调研 4：授课培训 5：纵向项目 6：横向项目
     */
    @Column
    private String activityProdType;

    /**
     * 承办单位
     */
    @Column
    private String undertaker;

    /**
     * 协办单位
     */
    @Column
    private String coorganizer;

    /**
     * 合作单位
     */
    @Column
    private String cooperator;

    /**
     * 主题
     */
    @Column
    private String theme;

    /**
     * 会议类型
     */
    @Column
    private String meetingType;

    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=meeting_type and t.type_key='MeetingType' and t.is_del = 0)")
    private String meetingTypeName;

    /**
     * 会议天数
     */
    @Column
    private Integer meetingDays;

    /**
     * 访问类型
     */
    @Column
    private String visitType;

    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=visit_type and t.type_key='VisitType' and t.is_del = 0)")
    private String visitTypeName;

    /**
     * 项目类别
     */
    @Column
    private String projectTypeParent;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=project_type_parent and t.type_key='ProcessType' and t.is_del = 0)")
    private String projectTypeParentName;

    @Column
    private String projectTypeChildren;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=project_type_children and t.type_key in (select c.d_code from biz_sysdict as c  where c.d_value=project_type_parent and c.type_key='ProcessType' and c.is_del = 0) and t.is_del = 0)")
    private String projectTypeChildrenName;

    /**
     * 合同金额
     */
    @Column
    private String contactFunds;

    /**
     * 批准经费
     */
    @Column
    private String approveFunds;

    /**
     * 已拨经费
     */
    @Column
    private String allocatedFunds;

    /**
     * 自筹经费
     */
    @Column
    private String selfraisedFunds;

    /**
     * 配套经费
     */
    @Column
    private String supportFunds;

    /**
     * 结余经费
     */
    @Column
    private String surplusFunds;

    /**
     * 项目状态
     */
    @Column
    private String projectStatus;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=project_status and t.type_key='ProgramProcess' and t.is_del = 0)")
    private String projectStatusName;

    /**
     * 甲方类型
     */
    @Column
    private String partyTypeParent;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=party_type_parent and t.type_key='PartyAType' and t.is_del = 0)")
    private String partyTypeParentName;

    @Column
    private String partyTypeChildren;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=party_type_children and t.type_key in (select c.d_code from biz_sysdict as c  where c.d_value=party_type_parent and c.type_key='PartyAType' and c.is_del = 0) and t.is_del = 0)")
    private String partyTypeChildrenName;

    /**
     * 联系人
     */
    private String linkMan;
    /**
     * 联系电话
     */
    private String linkPhoneNumber;
    /**
     * 联系地址
     */
    private String linkAddress;

    /**
     * 合同类别
     */
    @Column
    private String contractCategory;
    @Formula("(select t.d_name from biz_sysdict as t  where t.d_value=contract_category and t.type_key='ContractCategory' and t.is_del = 0)")
    private String contractCategoryName;


    /**
     * 其他作者
     */
    @Column
    private String otherAuthor;

    /**
     * 通讯作者
     */
    @Column
    private String communicationAuthor;

    /**
     * 项目id
     */
    @Column
    private Long projectId;

    /**
     * 是否智库专报  1:否
     */
    @Column
    private String isSpecialSub;

    /**
     * 智库专报来源: 自主上报、主旨论坛、政策沙龙、调研点建设
     */
    @Column(length = 2)
    private String specialSubSource;

    /**
     * 专报内容
     */
    @Column(columnDefinition = "text")
    @Lob
    private String bodyText;

    /**
     * 是否建设调研点 0:否  1:是
     */
    @Column
    private String isBuildResearch;

    @Column
    private String patentType;

    @Column
    private String researchField;

    @Column
    private String researchDirection;
    
    /**
     1：平台 2：知网
     */
    @Column
    private String fruitSource;
}

